// packageA/pages/ziliao.js
var t = getApp(),
  a = t.requirejs("core"),
  s = t.requirejs("wxParse/wxParse");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: 'https://7069-pinshang-ztqvr-1301803212.tcb.qcloud.la/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20200820104213.png?sign=40bd7fd48dbbee92338a39bf4452bde4&t=1597891362',
    link: '',
    tel: '',
    category: '',
    company: '',
    license: '',
    address: '',
    id: '0',
  },

  Inputcompany (e) {
    this.setData({
      company: e.detail.value
    })
    // console.log(this.data.company);
  },
  Inputlink (e) {
    this.setData({
      link: e.detail.value
    })
    // console.log(this.data.link);
  },
  Inputtel (e) {
    this.setData({
      tel: e.detail.value
    })
    // console.log(this.data.tel);
  },
  Inputcategory (e) {
    this.setData({
      category: e.detail.value
    })
    // console.log(this.data.category);
  },
  Inputaddress (e) {
    this.setData({
      address: e.detail.value
    })
    // console.log(this.data.address);
  },
  chooseImageTap2: function (e) {
    var id1 = a.pdata(e).id1;
    this.upload1(this, id1, 'chat_pic1');
  },
  fun_remove: function (e) {
    this.setData({
      license: ''
    })
  },
  upload1: function (that, field, n) {
    var _this = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#f7982a",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            _this.chooseWxImage1('album', that, field, n)
          } else if (res.tapIndex == 1) {
            _this.chooseWxImage1('camera', that, field, n)
          }

        }
      }
    })
  },
  chooseWxImage1: function (type_, that, field, n) {
    var _this = this,
      site = getApp().siteInfo,
      url = site.siteroot + '?i=' + site.uniacid + '&t=undefined&v=' + site.version + '&from=wxapp&c=entry&a=wxapp&do=index_uploadFile&path=' + n + '&m=yb_mingpian&sign=5201314';
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type_],
      count: 1,
      success: function (res) {

        console.log(res)
        wx.uploadFile({
          url: url,
          filePath: res.tempFilePaths[0],
          name: 'file_upload',
          success: function (res) {

            if (res.data != null && res.data != '') {
              console.log('事件的回顾跨境电商', res.data)
              that.setData({
                license: res.data,
              })
              // that.bindconfirm();
            } else {
              a.error('上传失败，请重试')
            }
          }
        })

      }
    })
  },
  upMycard: function () {
    var o = this
    //   console.log(o.data.link);
    //   console.log(o.data.tel);
    //   console.log(o.data.address);
    // console.log(o.data.company);
    // console.log(o.data.category);
    // console.log(o.data.license);
    let data = {
      uid: t.getCache("userinfo").uid,
      id: o.data.id,
      link: o.data.link,
      tel: o.data.tel,
      address: o.data.address,
      company: o.data.company,
      category: o.data.category,
      license: o.data.license,
      // head_photo: o.data.head_photo
    }
    a.get("Card/CompanyApply", data, function (res) {
      console.log(res)
      wx.showToast({
        title: res.info,
        icon: 'none',
      })
      // setTimeout(function () {
      wx.redirectTo({
        url: '/packageA/pages/progress',
      })
      // }.bind(o), 200)
      console.log(res)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.clickme()
  },
  clickme: function () {
    var o = this
    a.get("Card/CompanyEdit", {
      uid: getApp().getCache("userinfo").uid,
    }, function (res) {
      console.log(res)
      if (res.code == 0) {
        o.setData({
          address: res.info.address
        })
        o.setData({
          category: res.info.category
        })
        o.setData({
          tel: res.info.tel
        })
        o.setData({
          company: res.info.company
        })
        o.setData({
          license: res.info.license
        })
        o.setData({
          link: res.info.link
        })
        o.setData({
          id: res.info.id || 0
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})